package com.j2eefast.bussiness.contract.service;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.j2eefast.bussiness.contract.entity.BusArchivesEntity;
import com.j2eefast.bussiness.contract.entity.BusEquipmentEntity;
import com.j2eefast.bussiness.contract.entity.BusEquipmentRecordsEntity;
import com.j2eefast.bussiness.contract.entity.BusRepairEntity;
import com.j2eefast.bussiness.contract.mapper.BusEquipmentMapper;
import com.j2eefast.bussiness.contract.mapper.BusEquipmentRecordsMapper;
import com.j2eefast.bussiness.contract.mapper.BusRepairMapper;
import com.j2eefast.common.core.page.Query;
import com.j2eefast.common.core.utils.PageUtil;
import com.j2eefast.common.core.utils.ValidatorUtil;
import com.j2eefast.framework.annotation.DataFilter;
import com.j2eefast.framework.utils.Constant;
import com.j2eefast.framework.utils.UserUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;


/**
 * <p>维修管理</p>
 *
 * @author: summer
 * @date: 2021-05-31 14:41
 * @web: http://www.letukeji.cn
 * @version: 1.0.1
 */

@Service
public class BusEquipmentRecordsService extends ServiceImpl<BusEquipmentRecordsMapper, BusEquipmentRecordsEntity> {

    @Resource
    protected BusEquipmentRecordsMapper busEquipmentRecordsMapper;


//    /**
//    * 页面分页查询
//    */
//    public PageUtil findPage(Map<String, Object> params) {
//        QueryWrapper<BusEquipmentRecordsEntity> r = new QueryWrapper<BusEquipmentRecordsEntity>();
//        Page<BusEquipmentRecordsEntity> page = this.baseMapper.selectPage(new Query<BusEquipmentRecordsEntity>(params).getPage(),
//                r
//                );
//        return new PageUtil(page);
//    }

    /**
     * 页面分页查询
     */
    public PageUtil findPage(Map<String, Object> params) {
        String equipmentName = (String) params.get("equipmentName");
        String equipmentName2 = (String) params.get("equipmentName2");
        String equipmentModel = (String) params.get("equipmentModel");
        String equipmentModel2 = (String) params.get("equipmentModel2");
        String sampleCode = (String) params.get("sampleCode");
        String uses = (String) params.get("uses");
        String remark = (String) params.get("remark");
        String beginTime = (String) params.get("beginTime");
        String beginTime2 = (String) params.get("beginTime2");
        String endTime = (String) params.get("endTime");
        String endTime2 = (String) params.get("endTime2");
        Page<BusEquipmentRecordsEntity> page = busEquipmentRecordsMapper.findPage(
                new Query<BusEquipmentRecordsEntity>(params).getPage(),
                StrUtil.nullToDefault(equipmentName, ""),
                StrUtil.nullToDefault(equipmentName2, ""),
                StrUtil.nullToDefault(equipmentModel, ""),
                StrUtil.nullToDefault(equipmentModel2, ""),
                StrUtil.nullToDefault(sampleCode, ""),
                StrUtil.nullToDefault(uses, ""),
                StrUtil.nullToDefault(remark, ""),
                StrUtil.nullToDefault(beginTime, ""),
                StrUtil.nullToDefault(beginTime2, ""),
                StrUtil.nullToDefault(endTime, ""),
                StrUtil.nullToDefault(endTime2, ""),
                (String) params.get(Constant.SQL_FILTER));
        return new PageUtil(page);
    }




    public boolean deleteByIds(Long[] ids) {

        return busEquipmentRecordsMapper.deleteByIds(ids);

    }

    public boolean updateCheck(Long id) {
        Long userId= UserUtils.getUserInfo().getId();

        return busEquipmentRecordsMapper.updateCheck(id ,userId);

    }


    @DataFilter(compAlias="c",deptAlias = "d",userAlias = "u")
    public List<BusEquipmentRecordsEntity> findList(Map<String, Object> params) {
//        String name = (String) params.get("name");
//        String ceoName = (String) params.get("ceoName");
//        String paymentNuit = (String) params.get("paymentNuit");
//        String contractSum = (String) params.get("contractSum");
//        String projectName = (String) params.get("projectName");
        Long[] ids  = (Long[]) params.get("ids");
        return busEquipmentRecordsMapper.findList(
//                StrUtil.nullToDefault(name,""),
//                StrUtil.nullToDefault(ceoName,""),
//                StrUtil.nullToDefault(paymentNuit,""),
//                StrUtil.nullToDefault(projectName,""),
//                StrUtil.nullToDefault(contractSum,""),
                ids,
                (String) params.get(Constant.SQL_FILTER));
    }

    public boolean saves(BusEquipmentRecordsEntity busEquipmentRecordsEntity){
        System.out.println("111111111111111");
        System.out.println("111111111111111");
        System.out.println("111111111111111");
        Date date = new Date();//创建一个时间对象，获取到当前的时间
        busEquipmentRecordsEntity.setCreateTime(date);
        String userName=UserUtils.getUserInfo().getName();
        busEquipmentRecordsEntity.setCreateBy(userName);
        return this.save(busEquipmentRecordsEntity);
    }





}
